// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var dialog = require("dialog");
	var validate = require("validate");
	var leftMenu = require("../leftMenu/leftMenu");
    var topMenu = require("../topMenu/topMenu");
    var footer = require("../footer/footer_main");
	var bulletinId;
	var router = require("../hash/pageRouter");
	var fileSrc = "";
	var fileSize = '';
	var fileName = "";
	var css_detail = require("./announceDetail.css");
	var init = function(page) {
		bulletinId = page.params.bulletinId||base.getUrlParam("bulletinId");
		getAnnouceDetailInfo(bulletinId);
		footer.init();  
    	$("#footer").removeClass("none");
    	leftMenu.init(2);
    	topMenu.init(7);
    	router.init();
    	$(".leftMenu-item").removeClass("none");
    	$(".table-section").removeClass("none");
    	$(".footer").removeClass("none");
		initEvent();
	};
	var initEvent = function() {
		//若未登录，则返回登陆页面
		if(base.getData("sid")==null||base.getData("sid")==""||base.getData("sid")==undefined){
			top.location.href="../login/login.html";
		}
		
		$("#modify_announce").unbind("click").click(function(){
			router.route("announceModify/announceModify.html?bulletinId="+bulletinId);
		});
		
		$(".announceList").unbind("click").click(function(){
			  router.route("announceManage/platform_main_announcement_manager.html");
		});
	};
	
	//获取选中的公告信息
	var getAnnouceDetailInfo = function(bulletinId) {
		base.fnAjax({
			action: "inquireBulletinDetail.json",
			oData: {
				bulletinId: bulletinId
			},
			fnSuccess: function(data) {
				if (data.status == 200) {
					$("#annouce_title_detail").val(data.datas[0].title);
					$("#start_input_detail").val(data.datas[0].effectiveStartDate.substr(0, 10));
					$("#end_input_detail").val(data.datas[0].effectiveEndDate.substr(0, 10));
					$("#annouce_detail_detail").val(data.datas[0].content);
					$.each(data.datas[0].audiences, function() {
						switch (this) {
							case '2':
								$(".column_content").find($("#purchase_detail")).attr("checked", "checked");
								break;
							case '3':
								$(".column_content").find($("#supplier_detail")).attr("checked", "checked");
								break;
							case '1':
								$(".column_content").find($("#system_detail")).attr("checked", "checked");
								break;
							default:
								return "不详";
								break;
						}
					});
					
					for (var j = 0; j < data.datas[0].attachments.length; j++) {
						var row = data.datas[0].attachments;
						var txt = ['<div class="attach_list mb10" fileSrc="' + row[j].fileId + '" fileName="' + row[j].fileName + '" fileSize="' + row[j].fileSize + '">',
							'<div class="attach_logo"><img src="../../../res/images/icon/logo_attach.png"></div>',
							'<div class="attach_op">',
							'<a href="/finance/api/v1.0/downloadFile.file?fileUuid=' + row[j].fileId + '" download="' + row[j].fileName + '">',
							'<div class="attach_type">附件：' + row[j].fileName + '</div>',
							'<div class="attach_download">下载</div></a>',
							'<div class="hr"></div>',
						].join('');
						$("#attach_part").append(txt);
					}
				} else {
					util.alert(data.message);
				};
			}
		});
	};
	
	return {
		init: init
	};
});